<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增首页轮播广告')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: bootstrap-fileinput-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-advertise-add">
            <div class="form-group">
                <label class="col-sm-3 control-label">轮播名称：</label>
                <div class="col-sm-8">
                    <input name="name" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">轮播位置</label>
                <div class="col-sm-8">
                    <select name="type" class="form-control m-b" th:with="type=${@dict.getType('advertise_location')}">
                        <option value="">所有</option>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>

                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">轮播图片</label>
                <input name="pic" type="hidden">
                <div class="col-sm-8">
                    <div class="file-loading">
                        <input name="file" id="fileinput-demo-1" type="file" multiple>

                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">广告开始时间</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input name="startTime" class="form-control" placeholder="yyyy-MM-dd" type="text">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">广告结束时间</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input name="endTime" class="form-control" placeholder="yyyy-MM-dd" type="text">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">上下线状态</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('advertise_on_off')}">
                        <input type="radio" th:id="${dict.dictCode}" name="status" th:value="${dict.dictValue}">
                        <label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">链接地址：</label>
                <div class="col-sm-8">
                    <textarea name="url" class="form-control"></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="note" class="form-control"></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">排序：</label>
                <div class="col-sm-8">
                    <input name="sort" class="form-control" type="text">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: bootstrap-fileinput-js" />
    <script type="text/javascript">
        var prefix = ctx + "mall/advertise"
        $("#form-advertise-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-advertise-add').serialize());
            }
        }

        $("input[name='startTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='endTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("#fileinput-demo-1").fileinput({
            'theme': 'explorer-fas',
            'uploadUrl': ctx +'common/upload',
            overwriteInitial: false,
            autoReplace:true,
            initialPreviewAsData: true,
            initialPreview: [//初始显示图片列表
            ],
            uploadExtraData:{//额外参数，将不同的文件存放不同的目录下
                "baseDir":"advertise"
            }
        }).on("fileuploaded", function(event, data, previewId, index) {//上传成功回调
            $("input[name='pic']").val(data.response.url);
            console.log(data.response.url);
        });

    </script>
</body>
</html>
